const Base = require('./base.js');

module.exports = class extends Base {
	constructor(ctx) {
		super(ctx);
		this.message = this.model("system/message");
	}
	async indexAction() {
		if(this.isGet) {
			return this.display();
		}

		let posts = this.post();
		let where = {};
		if(!think.isEmpty(posts.type)) {
			where.type = posts.type;
		}
		let fields = "id, type, content, user_id, create_time, is_notified, platform";
		const data = await this.message.joinUserTable(posts,where,fields);
		return this.json(data);

	}

	
	async deleteAction() {

		let id = this.post("id");
		let rows = await this.message.where({
			id: id
		}).delete();
		if(rows == 0) {
			return this.fail("删除失败");
		}
		return this.success("删除成功");

	}
};